import axios from "@/utils/request.js";

/**
 * 分页查询用户信息
 * @param currentPage
 * @param pageSize
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const userPageService = (pageNo,pageSize,userId,nameFuzzy,grade) => {
  return axios.get("/userInfo/loadDataList",{params:{
      pageNo, pageSize, userId, nameFuzzy, grade
    }})
}

/**
 * 根据userId查询用户信息
 * @param {*} userId 
 * @returns 
 */
export const userSelectService = (userId) => {
  return axios.get("/userInfo/getUserInfoByUserId",{params:{
    userId
  }})
}

/**
 * 添加队员
 * @param userAddForm
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const userAddService = (userAddForm) => {
  return axios.post("/userInfo/add",userAddForm)
}

/**
 * 批量添加队员
 * @param userAddFormList
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const userAddBatchService = (listBean) => {
  return axios.post("/userInfo/addBatch",listBean)
}

/**
 * 修改用户信息
 * @type {userModifyService}
 */
export const userModifyService = (userInfo => {
  return axios.put("/userInfo/updateUserInfoByUserId",userInfo)
})

/**
 * 根据学号数组删除队员
 * @param userIds
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const userDeleteService = (list) => {
  return axios.post("/userInfo/deleteUserInfoBatchByUserId",list)
}

/**
 * 将当前查询到的所有队员信息导出Excel表格
 * @param {*} pageNo 
 * @param {*} pageSize 
 * @param {*} userIdFuzzy 
 * @param {*} nameFuzzy 
 * @param {*} grade 
 * @returns 
 */
export const userExportService = (pageNo,pageSize,userId, nameFuzzy, grade) => {
  return axios({
    url: "/userInfo/downloadExcel", // 后端提供文件的URL
    method: 'GET',
    responseType: 'blob', // 确保响应类型为blob
    params: {
        pageNo,
        pageSize,
        userId,
        nameFuzzy,
        grade
    }
  })
}

/**
 * 将Excel表格导入队员数据(已在MemberEnter中内置，但未调用到该文件中定义的api)
 * @param file
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const userImportService = (file) => {
  return axios.post("/userInfo/uploadExcel",file,{
    headers: {
      'token': localStorage.getItem('token')
    }
  })
}

/**
 * 获取所有队员的id和姓名
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const userSelectIdAndNameService = () => {
    return axios.get("/user/selectIdAndName")
}

/**
 * 查询所有队员人数（用于echarts图渲染）
 * @returns {Promise<axios.AxiosResponse<any>>}
 */
export const userCountAllService = () => {
  return axios.get("/user/countAll")
}
